package com.itheima.mall.api.pms;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mall.mapper.pms.SkuStockMapper;
import com.itheima.mall.pojo.pms.Product;
import com.itheima.mall.pojo.pms.SkuStock;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SkuStockServiceApiImpl implements SkuStockServiceApi{
    @Autowired
    private SkuStockMapper skuStockMapper;

    //根据商品ID及sku编码模糊搜索sku库存
    @Override
    public List<SkuStock> selectID(Integer pid, String keyword) {
        Long id =Convert.toLong(pid);
        LambdaQueryWrapper<SkuStock>wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SkuStock::getProductId,id);
        wrapper.like(StrUtil.isNotEmpty(keyword),SkuStock::getSkuCode,keyword);
        return skuStockMapper.selectList(wrapper);
    }

    //批量更新sku库存信息
    @Override
    public void updateSku(SkuStock skuStock) {
        skuStockMapper.updateById(skuStock);
    }


}
